<?php
/**
 * Using: 
 * 	$tip = DomFgToolTip::c()->title($banner->name)->contents($banner->getBannerHtml(''))->elementId('banner_'.$i);
 * 
 * @author Oliver Leisalu, Inditel Meedia
 * @package DomFg
 * @subpackage Input
 */
class DomFgToolTip {
	
	/**
	 * @var String
	 */
	public $title;
	/**
	 * @var String
	 */
	public $contents;
	/**
	 * @var String
	 */
	public $elementId;
	/**
	 * @var DomFgToolTip[]
	 */
	public static $tips = array();
	
	
	public function __construct() {
		self::$tips[] = $this;
	}
	
	public static function c() {
		return new DomFgToolTip();
	}
	
	public function title( $title ) {
		$this->title = $title;
		return $this;
	}
	
	public function contents( $contents ) {
		$this->contents = $contents;
		$this->contents = str_replace("\n","",$this->contents);
		$this->contents = str_replace("\r","",$this->contents);
		return $this;
	}
	
	public function elementId( $elementId ) {
		$this->elementId = $elementId;
		return $this;
	}
	
	/**
	 * Returns all currently active tooltips list and resets tooltips array.
	 *
	 * @return String
	 */
	public static function getTooltipsHtml() {
		$list = '<script type="text/javascript">';
		foreach( self::$tips as $i => $tip ) {
			$list .= "document.getElementById(\"$tip->elementId\").onmouseover=function() {tip.show('$tip->elementId','".addslashes($tip->title)."','".addslashes($tip->contents)."')};
			";
		}
		$list .= "</script>";
		self::$tips = array();
		return $list;
	}
	
}
?>